﻿using System.Linq;
using System.Web;
using System.Xml.Linq;

namespace GONES.Tools.Common
{
    public class GlobalSettings
    {
        private static GlobalSettings _globalSettings;

        private readonly string _defaultPassWord="000000";
        private readonly string _fileFtp="";
        private readonly string _fileServerUrl="";
        private readonly string _helpUrl="";
        private readonly string _organizer="";
        private readonly string _upfileType=@".JPG.GIF.PNG.JPEG.DOC.DOCX.XLS.XLSX.PPT.PPTX.RAR.";
        private readonly string _version="";
        private readonly bool _enableDbStore = false;
        private readonly string _dbName = "";
        private readonly string _backPath = "";

        private GlobalSettings()
        {
            XDocument xml = XDocument.Load(HttpContext.Current.Server.MapPath("~/Configs/GlobalSettings.xml"));
            _version =xml.Root.Elements("node").Where(n => n.Attribute("name").Value == "Version").First().Attribute("value").Value;
            _defaultPassWord = xml.Root.Elements("node").Where(n => n.Attribute("name").Value == "DefaultPassWord").First().Attribute("value").Value;
            _organizer =xml.Root.Elements("node").Where(n => n.Attribute("name").Value == "Organizer").First().Attribute("value").Value;
            _fileFtp = xml.Root.Elements("node").Where(n => n.Attribute("name").Value == "FileFtp").First().Attribute("value").Value;
            _upfileType =xml.Root.Elements("node").Where(n => n.Attribute("name").Value == "UpFileType").First().Attribute("value").Value;
            _fileServerUrl =xml.Root.Elements("node").Where(n => n.Attribute("name").Value == "FileServerUrl").First().Attribute("value").Value;
            _helpUrl = xml.Root.Elements("node").Where(n => n.Attribute("name").Value == "HelpUrl").First().Attribute("value").Value;
            _enableDbStore = xml.Root.Elements("node").Where(n => n.Attribute("name").Value == "EnableDbStore").First().Attribute("value").Value.ToLower() == "true";
            _dbName = xml.Root.Elements("node").Where(n => n.Attribute("name").Value == "DbName").First().Attribute("value").Value;
            _backPath = xml.Root.Elements("node").Where(n => n.Attribute("name").Value == "BackPath").First().Attribute("value").Value;
        }

        //版本信息
        public string Version
        {
            get { return _version; }
        }

        //默认密码
        public string DefaultPassWord
        {
            get { return _defaultPassWord; }
        }

        //单位名称
        public string Organizer
        {
            get { return _organizer; }
        }

        //fpt上传地址
        public string FileFtp
        {
            get { return _fileFtp; }
        }

        //上传文件类型
        public string UpFileType
        {
            get { return _upfileType; }
        }

        //上传服务器Url
        public string FileServerUrl
        {
            get { return _fileServerUrl; }
        }

        //帮助中心Url
        public string HelpUrl
        {
            get { return _helpUrl; }
        }

        //是否使用数据库存放图片
        public bool EnableDbStore
        {
            get { return _enableDbStore; }
        }

        //数据库名称
        public string DbName
        {
            get { return _dbName; }
        }

        //数据库备份位置
        public string BackPath
        {
            get { return _backPath; }
        }


      
        public static GlobalSettings Instance
        {
            get { return _globalSettings ?? (_globalSettings = new GlobalSettings()); }
        }
        
      

    }
}